const formatTime = time => {
    const date = new Date(time);
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours();
    const minute = date.getMinutes();
    const second = date.getSeconds();

    return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second]
        .map(formatNumber)
        .join(':')}`;
};

const formatNumber = n => {
    n = n.toString();
    return n[1] ? n : `0${n}`;
};

const errorFun = err => {
    wx.showModal({
        title: '温馨提示',
        content: JSON.stringify(err),
        showCancel: false,
        cancelText: '取消',
        cancelColor: '#000000',
        confirmText: '确定',
        confirmColor: '#3CC51F',
    });
};

module.exports = {
    formatTime,
    errorFun,
};
